{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from pprint import pprint\n",
    "from github import Github\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Example Call: `Show USER PROFILE in URL`\n",
    "> `https://api.github.com/users/RichardAfolabi` (in browser) <br>\n",
    "> `curl -i https://api.github.com/users/RichardAfolabi` (in shell)\n",
    "> All API calls: `https://api.github.com` (in browser) or `curl -i https://api.github.com` (in shell)\n",
    "\n",
    "Load Github token (Created at https://github.com/settings/tokens)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Load Github token \n",
    "github_token = pd.read_csv(\"../github_token.csv\")\n",
    "ACCESS_TOKEN = github_token.values.flatten()[0]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Dig deeper into `User = apache` and `Repo = spark`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Set user and repo of interest\n",
    "USER = 'apache'\n",
    "REPO = 'spark'\n",
    "\n",
    "githubx = Github(ACCESS_TOKEN, per_page=100)\n",
    "user = githubx.get_user(USER)\n",
    "repo = user.get_repo(REPO)\n",
    "\n",
    "\n",
    "# Retrieve key facts from the user - Apache. \n",
    "# repos_apache = [repo.name for repo in githubx.get_user('apache').get_repos()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " User 'apache' has 747 repos \n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Retrieve key facts from the user - Apache.\n",
    "# apache_repos = [repo.name for repo in repos]\n",
    "repos_apache = [rp.name for rp in githubx.get_user('apache').get_repos()]\n",
    "print(\"\\n User '{}' has {} repos \\n\".format(USER, len(apache_repos)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Check if project Spark exists\n",
    "'spark' in apache_repos"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Retrieve key facts from the Spark repository"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Programming Languages used under the `Spark` project are: \n",
      "\n",
      "{u'Batchfile': 4965,\n",
      " u'C': 533730,\n",
      " u'C++': 662044,\n",
      " u'CSS': 4016,\n",
      " u'HTML': 40639,\n",
      " u'Java': 3993431,\n",
      " u'JavaScript': 239387,\n",
      " u'M4': 46802,\n",
      " u'Makefile': 10886,\n",
      " u'Mako': 13678,\n",
      " u'Perl': 113430,\n",
      " u'Perl6': 36004,\n",
      " u'Python': 128354,\n",
      " u'Shell': 73438,\n",
      " u'XS': 66352,\n",
      " u'XSLT': 6024}\n"
     ]
    }
   ],
   "source": [
    "print(\"Programming Languages used under the `Spark` project are: \\n\")\n",
    "pp(rp.get_languages())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of Stargazers is 7973\n"
     ]
    }
   ],
   "source": [
    "stargazers = [s for s in repo.get_stargazers()]\n",
    "print(\"Number of Stargazers is {}\".format(len(stargazers)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[u'mateiz',\n",
       " u'beyang',\n",
       " u'abo',\n",
       " u'CodingCat',\n",
       " u'andy327',\n",
       " u'CrazyJvm',\n",
       " u'jyotiska',\n",
       " u'BaiGang',\n",
       " u'sundstei',\n",
       " u'dianacarroll',\n",
       " u'ybotco',\n",
       " u'xelax',\n",
       " u'invkrh',\n",
       " u'bedla',\n",
       " u'nadesai',\n",
       " u'pcpratts',\n",
       " u'narkisr',\n",
       " u'Honghe',\n",
       " u'Jacke',\n",
       " u'xiajunluan']"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Retrieve a few key participants of the wide Spark GitHub repository network.\n",
    "# The first stargazer is Matei Zaharia, the cofounder of the Spark project when he was doing his PhD in Berkeley.\n",
    "\n",
    "[stargazers[i].login for i in range(0,20)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
